package whu.cn.whushare.ui.main.my;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.androidplus.util.StringUtil;
import com.androidplus.util.ViewMapping;
import com.androidplus.util.ViewMappingUtil;

import whu.cn.whushare.R;
import whu.cn.whushare.common.UserManager;
import whu.cn.whushare.net.DownloadParams;
import whu.cn.whushare.net.Downloader;
import whu.cn.whushare.ui.common.BaseActivity;

/**
 * Created by xiaoping on 2015/1/30.
 */
@ViewMapping(id= R.layout.activity_myinfo_title_change)
public class InfoTitleChangeActivity  extends BaseActivity {
    @ViewMapping(id = R.id.title_change)
    private EditText mTitleChange;
    private UserManager mUserManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initViewsAndActions();
    }
    public static Intent getStartIntent(Context context) {
        Intent i = new Intent(context, InfoTitleChangeActivity.class);

        return i;
    }

    private void initViewsAndActions() {
        View root = ViewMappingUtil.mapView(this, this);
        mUserManager = UserManager.getInstance(this);
        getTopBar(root);
        mTopBar.title.setText(R.string.my_info_title_change);
        mTopBar.rightText.setVisibility(View.VISIBLE);
        mTopBar.rightText.setText(R.string.save);
        initAction();
    }


    private void initAction() {
        mTopBar.rightText.setOnClickListener(this);


    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.top_right_txt:
                String position = mTitleChange.getText().toString();
               Downloader.getInstance(this).changeTitle(position,this);

                break;
            default:
                break;
        }
    }

    public <T> void onSuccess(DownloadParams.PARSING_TYPE type, T response, Object obj) {
        super.onSuccess(type, response, obj);

        switch (type) {
            case CHANGE_TITLE:
                toast("修改成功！");
                startActivity(MyInfoActivity.getStartIntent(this));
                break;

            default:
                break;

        }

    }

}

